#include <iostream>
#include <algorithm>
#include <string>
#include <array>

template<size_t N>
struct StringLiteral {
    constexpr StringLiteral(const char (&str)[N]) {
        std::copy_n(str, N, value);
        len = N;
        cnt = std::count(std::begin(str), std::end(str), '%');
    }

    char value[N];
    size_t len;
    uint32_t cnt;
};

template<StringLiteral lit>
void Print() {
    // The size of the string is available as a constant expression.
    constexpr auto size = sizeof(lit.value);

    // and so is the string's content.
    constexpr auto contents = lit.value;

    std::cout << "Size: " << size << ", Contents: " << contents << std::endl;
}

template<StringLiteral lit>
constexpr auto GetNewStr() {
    std::string newStr(lit.value);
    std::array<char, lit.len + lit.cnt * 8> ret{};
    size_t pos = 0;
    while (true) {
        pos = newStr.find('%', pos);
        if (pos == std::string::npos) {
            break;
        }
        newStr.insert(++pos, "{public}");
    }
    std::copy(newStr.begin(), newStr.end(), ret.begin());
    return ret;
}

int main() {
    // Print<"literal string">(); // Prints "Size: 15, Contents: literal string"
    constexpr auto s = GetNewStr<"%s %d">();
    printf("%s", s.data());
}